Crate bevy_yarnspinner

source ·
Expand description

§Bevy Yarn Spinner

This is the Bevy integration for Yarn Spinner, the friendly dialogue creation tool for Rust. It allows you to easily create dialogue systems in your game.

§Usage

The three main types you will interact with are:

§Dialogue Views

The dialogue runner itself does not draw anything to the screen, it only tells you what content to present. Any plugin that handles the actual drawing is called a dialogue view. We provide an example dialogue view that you can use to explore the features of Yarn Spinner and get started quickly.

Specifically, a dialogue view is required to do the following things

See the documentation for the events module for additional optional events that may be handled

Note that while DialogueRunners are setup in such a way that you can have multiple instances running in parallel (such as for split-screen co-op), a general-purpose dialogue view is not required to support this use-case, as every game that does this will have it’s own way of wanting to deal with this. In particular, the example dialogue view only supports a single DialogueRunner.

§Demo

You can play a the Yarn Spinner for Rust Demo in your browser to see the aforementioned example dialogue view in action. Additionally, there are many examples that you can check out.

§Example

The main workflow is as follows:

The following example is adapted from the hello world example.

# assets/dialogue/hello_world.yarn
title: Start
---
Hello world!
===
// src/main.rs
use bevy::{prelude::*, utils::Duration};
use bevy_yarnspinner::prelude::*;
// Use the example dialogue view to see the dialogue in action. Requires the `bevy_yarnspinner_example_dialogue_view` crate.
// use bevy_yarnspinner_example_dialogue_view::prelude::*;

fn main() {
    let mut app = App::new();
    app.add_plugins((
        // Add the Yarn Spinner plugin.
        // As soon as this plugin is built, a Yarn project will be compiled
        // from all Yarn files found under assets/dialog/*.yarn
        YarnSpinnerPlugin::new(),
        // Initialize the bundled example UI. Requires the `bevy_yarnspinner_example_dialogue_view` crate.
        // ExampleYarnSpinnerDialogueViewPlugin::new(),
    ))
    // Setup a 2D camera so we can see the text
    .add_systems(Startup, setup_camera)
    // Spawn the dialog as soon as the Yarn project finished compiling
    .add_systems(
        Update,
        spawn_dialogue_runner.run_if(resource_added::<YarnProject>),
    )
    .run();
}

fn setup_camera(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
    let mut dialogue_runner = project.create_dialogue_runner();
    // Start the dialog at the node with the title "Start"
    dialogue_runner.start_node("Start");
    commands.spawn(dialogue_runner);
}

Modules§

Macros§

Structs§

Traits§

Type Aliases§